import os
import tensorflow as tf

# 求 y = 3x*x + 2x + 1 在 x = 3 时的导数
# y‘ = 6x + 2


# 在 x = [1,3,5,7,9...99] 时对应的导数

if __name__ == '__main__':
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    # x = tf.Variable(initial_value=3.0)
    # with tf.GradientTape() as tape:
    #     y = 3 * tf.square(x) + 2 * x + 1
    #
    # y_grad = tape.gradient(y,x)
    # print(y)
    # print(y_grad)
    #
    # x = tf.Variable(initial_value=[i for i in range(1,100,2)])

    # for i in range(1, 100):
    #     if i % 2 == 1:
    #         print(i)

    # for i in range(1, 100, 2):
    #     print(i)

    numbers = [i for i in range(1, 100, 2)]
    # print(numbers)

    x = tf.Variable(initial_value=numbers, dtype=tf.float32)
    with tf.GradientTape() as tape:
        y = 3 * tf.square(x) + 2 * x + 1

    y_grad = tape.gradient(y,x)
    print(y)
    print(y_grad)





